<template>
    <div class="container">
        <!--头部-->
        <div class="top">
            <div class="left">
                <a @click="routerback"><img src="../assets/img/back.png"><span class="category">{{search.title}}</span></a>
            </div>
            <div class="right">
                <router-link to="/index"><span>书城</span><img src="../assets/img/home.png"></router-link>
            </div>
        </div>
        <!--书籍显示-->
        <div id="vue-center" class="center">
            <div class="intro" v-for="book in books" :key="book.ID">
                <router-link :to="{path:'/book_details',query:{id:book.ID}}">
                    <div class="intro_tu">
                        <img :src="book.ImageUrl">
                    </div>
                    <div class="intro_right">
                        <p class="intro_title">{{book.Title}}</p>
                        <p class="intro_intro">{{book.Description}}</p>
                        <span class="intro_fenlei">{{book.TagName}}</span>
                    </div>
                </router-link>
            </div>
            <div class="meiyou"  v-if="none">没有更多图书了</div>
            <div class="see_more" v-if="more" @click="next_search">
                点击查看更多
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "classify",
        data(){
            return{
                search:{
                    offset: 0,
                    limit: 15,
                    order: this.$route.query.order,
                    sex: this.$route.query.sex,
                    title: this.$route.query.title,
                    tag_name: this.$route.query.TagName, // 标签 ID
                },
                books: [], // 显示的图书列表
                none: false,
                more: false,
            }
        },
        created:function(){
            this.set()
            this.start_search()
            document.title = this.search.title;
        },
        methods: {
            set:function(){
                this.$emit('set','hide')
            },
            routerback: function () {
                this.$router.back(-1)
            },
            // 开始搜索
            start_search: function(push) {
                this.$axios.get('/books',{params:{ForbidView:2,Sex:this.search.sex,Limit:this.search.limit,Offset:this.search.offset,Order:this.search.order,TagName:this.search.tag_name,Descending:true}}).then(response=>{
                    if(response) {
                        if(response.data.books.length < this.search.limit){
                            this.none = true
                            this.more = false
                        }else{
                            this.none = false
                            this.more = true
                        }
                        if(push) {
                            for(let i = 0, ln = response.data.books.length; i < ln; i++) {
                                this.books.push(response.data.books[i])
                            }
                        } else {
                            this.books = response.data.books;
                        }
                    } else {
                        this.more = false
                        this.none = true
                    }
                })
            },
            next_search: function() {
                this.search.offset += this.search.limit;
                this.start_search(true);
            }
        }
    }
</script>

<style scoped>
    .container {
        background: white;
        margin-bottom: 20px;
        padding: 0px;
    }
    .meiyou {
        text-align: center;
        padding: 20px 0px 5px;
        color: #999;
    }
    .top {
        margin-bottom: 15px;
        padding: 10px 0px;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        background: #ebebeb;
    }

    .left a {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
    }

    .right a {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
    }

    .left a,
    .right a {
        color: black;
        text-decoration: none;
    }

    .top img {
        width: 2.5rem;
    }

    .top span {
        font-size: 1.1rem;
    }

    .intro a {
        margin-top: 20px;
        display: flex;
        text-decoration: none;
        color: black;
    }

    .intro img {
        width: 6.5rem;
        height: 8.7rem;
        -webkit-box-shadow: 0 4px 10px rgba(0,0,0,.2);
        box-shadow: 0 4px 10px rgba(0,0,0,.2);
    }
    .intro_tu{
        margin-left: 15px;
    }
    .intro_right {
        margin: 0px 15px;
    }

    .intro_title {
        font-size: 1.2rem;
        margin: 0px;
    }

    .intro_writer {
        color: #c1c1c1;
        font-size: 10px;
    }

    .intro_intro {
        margin: 13px 0px;
        color: #999;
        font-size: 1rem;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .intro_fenlei {
        text-align: center;
        font-size: 1rem;
        color: #989898;
    }

    .see_more {
        margin: 20px 13px 10px;
        padding: 12px 0px;
        background: #3688ff;
        border-radius: 5px;
        text-align: center;
        color: white;
        font-size: 16px;
    }

    @media (min-width: 300px) {
        .container {
            width: 100%;
        }
    }

    @media (min-width: 768px) {
        .container {
            width: 750px;
        }
        .intro img {
            width: 8rem;
            height: 11rem;
            margin-left: 15%;
        }
        .intro_right {
            margin-top: 7px;
        }
        .intro_title {
            font-size: 1.4rem;
        }
    }
</style>
